<template>
	<view class="fui-wrap">
		<fui-sticky>
			<view style="background-color: #fff;">
				<fui-segmented-control @click="changeSegmented" :current="current" color="#000" activeColor="#0a8cdd" type="text" :values="segmented"></fui-segmented-control>
			</view>
		</fui-sticky>
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" arrow :key="index" @click="$navigateTo('merchant/coupondetail?id='+item.id)">
				<view class="cell">
					<view class="item">
						<view class="line">
							<fui-text style="width: 140rpx;" align="right" block text="发券时间：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.createtime" color="#000" :size="28"></fui-text>
						</view>
						<view class="line">
							<fui-text style="width: 140rpx;" align="right" block text="停车券：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.coupon.title" color="#000" :size="28"></fui-text>
						</view>
						<view class="line" v-if="item.remark">
							<fui-text style="width: 140rpx;" align="right" block text="备注：" color="#afafaf" :size="28"></fui-text>
							<fui-text :text="item.remark" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="status">
						<fui-text :text="item.plate_number" color="#000" :size="28"></fui-text>
					</view>
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<fui-top-popup :show="showPopup" :zIndex="9999" :radius="0">
			<view class="fui-custom__wrap">
				<fui-input v-model="keywords" :inputBorder="true" placeholder="请输入车牌号" :size="28" :padding="['16rpx','20rpx']"></fui-input>
				<view class="bottom">
					<fui-button @click="confirm" height="80rpx" :margin="['30rpx']">提交</fui-button>
					<fui-button @click="cancel" height="80rpx" type="gray" :margin="['30rpx']">取消</fui-button>
				</view>
			</view>
		</fui-top-popup>
		<pcfooter :search="true" @search="showPopup=true;"></pcfooter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDateTime} from '@/utils/util.js';
	import plateType from '@/components/common/platetype.vue';
	import pcfooter from '@/components/common/pcfooter.vue';
	export default {
		components:{
			plateType:plateType,
			pcfooter:pcfooter
		},
		data() {
			return {
				baseUrl:baseUrl,
				segmented:['未使用','已使用','使用中','已过期','已作废'],
				current:0,
				page:1,
				endData:false,
				list:[],
				showPopup:false,
				keywords:'',
				platform:''
			}
		},
		onLoad(e) {
			this.$platform();
			this.getCouponList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getCouponList(function(){
				uni.stopPullDownRefresh();
			});
		},
		onReachBottom() {
			this.getCouponList();
		},
		methods: {
			...methods,
			changeSegmented:function(e){
				this.current=e.index;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getCouponList();
			},
			getCouponList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('merchant/coupon/list',{
					type:this.current,
					keywords:this.keywords,
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			},
			formatDateTime:function(e){
				let r=formatDateTime(new Date(e*1000));
				return r.slice(0,16);
			},
			confirm:function(){
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getCouponList();
			},
			cancel:function(){
				this.showPopup=false;
				this.keywords='';
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fui-wrap{
		padding-top: 0rpx;
	}
	.fui-custom__wrap{
		margin-top: 30rpx;
		padding: 20rpx 48rpx;
		padding-top: 0;
	}
	.cell{
		width:100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.item{
		width: 75%;
		.line{
			display: flex;
			height: 50rpx;
		}
	}
	.status{
		width: 25%;
		text-align: right;
	}
</style>